﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Deployment.Data.UI.Controls.Variable
{
    /// <summary>
    /// Interaction logic for VariableEditorControl.xaml
    /// </summary>
    public partial class VariablesEditorControl : UserControl, INotifyPropertyChanged
    {
        public static readonly DependencyProperty VariablesFilePathProperty =
            DependencyProperty.Register("VariablesFilePath",
                typeof(string),
                typeof(VariablesEditorControl));

        //public static readonly DependencyProperty EnvironmentsProperty =
        //    DependencyProperty.Register("Environments",
        //        typeof(Data.Environment.EnvironmentsFile),
        //        typeof(VariablesEditorControl));

        public static readonly DependencyProperty HasUnsavedChangesProperty =
            DependencyProperty.Register("HasUnsavedChanges",
                typeof(bool),
                typeof(VariablesEditorControl));

        //public static readonly DependencyProperty VariablesPropery =
        //    DependencyProperty.Register("Variables",
        //        typeof(Data.Variable.VariablesFile),
        //        typeof(VariablesEditorControl), new PropertyMetadata(new Data.Variable.VariablesFile()));

        public event PropertyChangedEventHandler PropertyChanged;
        private void OnPropertyChanged(DependencyProperty property)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(property.Name));
        }

        private void SetValueDp(DependencyProperty property, object value)
        {
            SetValue(property, value);
            OnPropertyChanged(property);
        }

        public VariablesEditorControl()
        {
            InitializeComponent();
            this.DataContext = this;
        }

        public string VariablesFilePath
        {
            get { return (string)GetValue(VariablesFilePathProperty); }
            set { SetValueDp(VariablesFilePathProperty, value); }
        }

        public bool HasUnsavedChanges
        {
            get { return (bool)GetValue(HasContentProperty); }
            set { SetValueDp(HasContentProperty, value); }
        }

        public Data.Environment.EnvironmentsFile Environments
        {
            get 
            { 
                //return (Data.Environment.EnvironmentsFile)GetValue(EnvironmentsProperty); 
                return EditableList.Environments;
            }
            set 
            { 
                //SetValueDp(EnvironmentsProperty, value); 
                EditableList.Environments = value;
            }
        }

        public Data.Variable.VariablesFile Variables
        {
            get 
            { 
                //return (Data.Variable.VariablesFile)GetValue(VariablesPropery); 
                return EditableList.Variables;
            }
            set 
            { 
                //SetValueDp(VariablesPropery, value); 
                EditableList.Variables = value;
            }
        }

        
    }
}
